package demo4;

public class TestDemo4 {
    public static void main(String[] args) {
        running(new Dog("🐕",1));
        running(new Frog("🐸",1));
        running(new Duck("🦆",1));
        System.out.println("---------");
        flying(new Duck("🦆",1));
//        flying(new Dog("🐕",1));//error
//        flying(new Frog("🐸",1));//error
        System.out.println("---------");
//        swimming(new Dog("🐕",1));//error
        swimming(new Frog("🐸",1));
        swimming(new Duck("🦆",1));
        running(new Robot("qqq", 1));
    }
    public static void flying(IFly iFly) {
        iFly.fly();
    }
    public static void swimming(ISwim iSwim) {
        iSwim.swim();
    }
    public static void running(IRun iRun) {
        iRun.run();
    }
}

abstract class Animal {
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

interface IRun {
    void run();
}

interface ISwim {
    void swim();
}

interface IFly {
    void fly();
}

class Dog extends Animal implements IRun{

    public Dog(String name, int age) {
        super(name, age);
    }
    public void run() {
        System.out.println(this.name + "在摇着尾巴跑步");
    }
}

class Frog extends Animal implements ISwim,IRun {

    public Frog(String name, int age) {
        super(name, age);
    }

    @Override
    public void run() {
        System.out.println(this.name + "在用两条腿跳");
    }

    @Override
    public void swim() {
        System.out.println(this.name + "在蛙泳");
    }
}

class Duck extends Animal implements IRun,ISwim,IFly {
    public Duck(String name, int age) {
        super(name, age);
    }

    @Override
    public void run() {
        System.out.println(this.name + "在摇着屁股再跑");
    }


    @Override
    public void swim() {
        System.out.println(this.name + "在鸭泳");
    }

    @Override
    public void fly() {
        System.out.println(this.name + "在飞行");
    }
}

class Robot extends Animal implements IRun {
    public Robot(String name, int age) {
        super(name, age);
    }

    @Override
    public void run() {
        System.out.println("机器人在跑");
    }
}
